/*
 * XUtilsTest.java
 * 
 * Copyright (c) 2005 - 2007
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.xfc.util;

import java.awt.Rectangle;
import java.util.List;

import org.xfc.testing.XUITestCase;

/**
 * The class <code>XUtilsTest</code> contains tests for the class {@link XUtils}.
 *
 * @author Devon Carew
 */
public class XUtilsTest
	extends XUITestCase
{
	
	public void testConvertToRectangle_1()
	{
		java.awt.Rectangle result = XUtils.convertToRectangle("");
		assertEquals(null, result);
	}

	public void testConvertToRectangle_2()
	{
		Rectangle result = XUtils.convertToRectangle("0,0,0,0");
		assertEquals(new Rectangle(0, 0, 0, 0), result);
	}

	public void testConvertToString_1()
	{
		String result = XUtils.convertToString(null);
		assertEquals(null, result);
	}

	public void testConvertToString_2()
	{
		String result = XUtils.convertToString(new Rectangle());
		assertEquals("0,0,0,0", result);
	}

	public void testGetPackageName_1()
	{
		String result = XUtils.getPackageName(Number.class);
		assertEquals("java.lang", result);
	}

	public void testGetPackageName_2()
	{
		String result = XUtils.getPackageName(Object.class);
		assertEquals("java.lang", result);
	}

	public void testGetPackageName_3()
	{
		String result = XUtils.getPackageName(List.class);
		assertEquals("java.util", result);
	}

	public void testGetShortName_1()
	{
		String result = XUtils.getShortName(Number.class);
		assertEquals("Number", result);
	}

	public void testGetShortName_2()
	{
		String result = XUtils.getShortName(Object.class);
		assertEquals("Object", result);
	}

	public void testGetShortName_3()
	{
		String result = XUtils.getShortName(List.class);
		assertEquals("List", result);
	}
	
	public void testLoremIpsumText()
	{
		assertNotNull(XUtils.getLoremIpsumText());
		assertTrue(XUtils.getLoremIpsumText(100).length() > 80);
	}
	
	public void testSafeEquals()
	{
		assertFalse(XUtils.safeEquals(null, "dssdf"));
		assertFalse(XUtils.safeEquals("sdfsdf", null));
		assertTrue(XUtils.safeEquals(null, null));
		assertTrue(XUtils.safeEquals("sdsdf", "sdsdf"));
		assertFalse(XUtils.safeEquals("sdsdf", "sdfssdfdd"));
	}
	
	public void testGetJavaVersion()
	{
		assertTrue(XUtils.getMajorJavaVersion() >= 1.4);
		assertTrue(XUtils.getMinorJavaVersion() >= 0);
	}
	
	public void testGetVirtualDisplayBounds()
	{
		Rectangle bounds = XUtils.getVirtualDisplayBounds();
		
		assertTrue(bounds.getWidth() >= 100);
		assertTrue(bounds.getHeight() >= 100);
	}
	
	public void testInvokeAndWait()
	{
		XResultRunnable runnable = new XResultRunnable() {
			public Object run() {
				return "testResult";
			}
		};
		
		Object result = XUtils.invokeAndWait(runnable);
		
		assertEquals("bad result from invokeAndWait()", "testResult", result);
	}
	
}
